package com.tkjt.pms.modules.common.service.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tkjt.pms.calc.core.CalcStatusWatcher;
import com.tkjt.pms.modules.common.service.PMSTaskService;

@Service("pmsTaskService")
public class PMSTaskServiceImpl implements PMSTaskService {

//	@Autowired
//	private ExecutorInfo executorInfo;
	
	@Autowired
	private CalcStatusWatcher calcStatusWatcher;
	
	@Override
	public Map<String, String> getTaskStatus(String taskCode, String indexGroup, String indexYearMonth) {
		Map<String, String> statusMap = new HashMap<String, String>();
		
		try {
			boolean isCalcOngoing = calcStatusWatcher.haveCalcOngoing(null, indexYearMonth, new HashSet<String>());
			if(!isCalcOngoing) {
				//状态结束
				statusMap.put("tcResult", "0");
				statusMap.put("tcResultMsg", "任务完成");
			} else {
				//状态进行中
				statusMap.put("tcResult", "1");
				statusMap.put("tcResultMsg", "任务进行中");
			}
		} catch(Exception e) {
			//状态异常
			statusMap.put("tcResult", "2");
			statusMap.put("tcResultMsg", "任务异常");
		}
		
		statusMap.put("taskCode", taskCode);
		statusMap.put("indexYearMonth", indexYearMonth);
		
		return statusMap;
	}

}
